<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <p>请输入年份<input type="text" id="year"><input id="but" type="button" value="判断是否为闰年" onclick="getYear()"><span
            id="result"></span></p>
    <p>请输入月份<input type="text" id="month"></p>
    <p>请输入天数<input type="text" id="day"><input id="but" type="button" value="计算天数" onclick="getDay()"><span
            id="resultTwo"></span></p>

    <script>
        //1.输入年份判断改年是平年还是闰年
        function getYear() {
            let year = document.getElementById('year').value;
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                document.getElementById('result').innerHTML = '闰年';
            } else {
                document.getElementById('result').innerHTML = '平年';
            }
        }
        //3.根据输入的三个数字，判断是这一年的第几天
        function getDay() {
            let year = document.getElementById('year').value;
            let boo;
            if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                boo = true;
            } else {
                boo = false;
            }
            let month = document.getElementById('month').value;
            let day = document.getElementById('day').value;
            let monthArr = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
            let sumDay = 0; 
            monthArr.forEach(function (v, item, arr) {
                if ((month - 2) == item)
                    arr.length = 0;
                if (item == 1)
                    if (boo)
                        v = 29
                sumDay += v;
            });
            sumDay += parseInt(day);
            if (month == 1)
                sumDay = parseInt(day);
            document.getElementById('resultTwo').innerHTML = sumDay;
        }
    </script>
</body>

</html>